package com.lyh.societiesmanager.entity;

import lombok.Data;

@Data
public class Response<T> {
    private int code;       // 响应码
    private String message;  // 响应消息
    private T data;          // 响应数据

    // 成功响应的静态方法
    public static <T> Response<T> success(T data) {
        Response<T> response = new Response<>();
        response.setCode(200); // HTTP 200 表示成功
        response.setMessage("操作成功");
        response.setData(data);
        return response;
    }

    // 自定义消息的成功响应
    public static <T> Response<T> success(String message, T data) {
        Response<T> response = new Response<>();
        response.setCode(200);
        response.setMessage(message);
        response.setData(data);
        return response;
    }

    // 错误响应的静态方法
    public static <T> Response<T> error(int code, String message) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        response.setData(null);
        return response;
    }

    // 自定义数据和消息的错误响应
    public static <T> Response<T> error(int code, String message, T data) {
        Response<T> response = new Response<>();
        response.setCode(code);
        response.setMessage(message);
        response.setData(data);
        return response;
    }
}